package cn.edu.xjtu.competiton.lccp;

/**
 * @author Hydrion-QLz
 * @date 2022-04-16 15:00
 * @description
 */
public class First {
    public static void main(String[] args) {
        First solution = new First();
        int[] arr = {3, 1, 2};
        int[][] operations = {{0, 2}, {2, 1}, {2, 0}};
        System.out.println(solution.giveGem(arr, operations));
    }

    public int giveGem(int[] gem, int[][] operations) {
        for (int i = 0; i < operations.length; i++) {
            int x = operations[i][0];
            int y = operations[i][1];
            gem[y] += gem[x] / 2;
            gem[x] = gem[x] % 2 == 0 ? gem[x] / 2 : gem[x] / 2 + 1;
        }
        int max = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < gem.length; i++) {
            if (gem[i] > max) {
                max = gem[i];
            }
            if (gem[i] < min) {
                min = gem[i];
            }
        }
        return max - min;
    }
}
